<template>
    <div>
        <div class="top">
            <span @click="$router.back()">
                <van-icon name="arrow-left" />
            </span>
            <h3>搜索结果</h3>
        </div>
        <li v-for="item in list" :key="item._id">
        <p style="text-indent:2em">{{ item.title }}</p>
            
            <img :src="item.imageSrc">
            <div style="margin-left:5%;margin-top:10px">
                <van-col span="12" class="col333">作者：{{ item.author }}</van-col>
                <van-col span="10" class="col333">时间：{{ item.time | formatDate }}</van-col>
            </div>
        </li>



    </div>
</template>

<script>
import { Search } from 'vant';

// 接口
import { search } from '@/api/api'




export default {
    components: {
        [Search.name]: Search,
    },
    data() {
        return {
            list: []
        };
    },
    computed: {
        key_word() {
            return this.$route.query.key_word
        }
    },
    created() {
        this.getList()
    },
    methods: {
        getList() {
            let { key_word } = this;
            search({
                key_word
            }).then(res => {
                console.log(res)
                if (res.data.code == 0) {
                    this.list = res.data.data
                }
            })
        }
    },
    // 时间戳转换年月日
    filters: {
        formatDate: function (value) {
            let date = new Date(value);
            let y = date.getFullYear();
            let MM = date.getMonth() + 1;
            MM = MM < 10 ? "0" + MM : MM;
            let d = date.getDate();
            d = d < 10 ? "0" + d : d;
            return y + "-" + MM + "-" + d;
        }
    },
}
</script>

<style scoped>
img {
    width: 100%;
    margin-top: 10px;
}

li {
    list-style: none;
    margin: 20px 0;
    padding-bottom: 50px;
    border-bottom: 2px solid black;
}

.van-nav-bar__text {
    color: gray
}

.van-nav-bar__text {
    color: gray;
}

.top {
    width: 100%;
    height: 55px;
    background-color: #3399ff;
}

.top span {
    float: left;
    line-height: 55px;
    margin-left: 20px;
    color: white;
    font-size: 18px;
}

.top h3 {
    color: white;
    line-height: 55px;
    margin-top: 0;
    margin-right: 20px;
    text-align: center;
}
</style>